package adv6;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * @author oldliu
 * @since 1.0
 */
public class FileJiami {
    //一次读完
    public static void main(String[] args) {
        File f=new File("D:\\Documents\\桌面\\2019.jpg");

        try {
            FileInputStream fin=new FileInputStream(f);
            byte b[]=new byte[fin.available()];//文件不能太大
            int len= fin.read(b);//一次读

            fin.close();//先关闭。。。
            for (int i = 0; i < b.length; i++) {
                b[i]= (byte) ~b[i];
            }
            File f2 = new File(f.getParent(),f.getName()+"_bak");
            FileOutputStream fout=new FileOutputStream(f2);
            fout.write(b);
            fout.close();
            f.delete();
            f2.renameTo(f);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
